package com.mcptt.config.group.sub;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.product.log.Log;

public class SupportedServices {
	
	public static final String Name = "supported-services";
	public static final String Namespace_Oxe = "oxe";
	private static final String Name_Service = "service";
	private static final String Name_GroupMedia = "group-media";
	private static final String Name_enabler = "enabler";
	
	private String enabler = null;
	
	
	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			if(name.equals(Name_Service))
			{
				enabler = subElem.getAttributeValue(Name_enabler);
			}
		}  
	}
	
	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Namespace_Oxe).append(":").append(Name).append(">").append("\r\n");
		
		strBuf.append("    ").append("<").append(Namespace_Oxe).append(":").append(Name_Service).append(" ").append(Name_enabler).append("=\"").append(enabler).append("\">").append("\r\n");
		
		strBuf.append("        ").append("<").append(Namespace_Oxe).append(":").append(Name_GroupMedia).append(">").append("\r\n");
		strBuf.append("            ").append("<mcpttgi:mcptt-speech/>");
		strBuf.append("        ").append("</").append(Namespace_Oxe).append(":").append(Name_GroupMedia).append(">").append("\r\n");
		
		strBuf.append("    ").append("</").append(Namespace_Oxe).append(":").append(Name_Service).append(">").append("\r\n");
		strBuf.append("</").append(Namespace_Oxe).append(":").append(Name).append(">").append("\r\n");

		return strBuf.toString();
	}
}
